<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/themes/default/easyui.css"></link>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/themes/icon.css"></link>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/demo/demo.css"></link>
	<script language="JavaScript"  type="text/javascript" src="js/jquery-easyui-1.5/jquery.min.js"></script>
	<script language="JavaScript"  type="text/javascript" src="js/jquery-easyui-1.5/jquery.easyui.min.js"></script>
	<script language="JavaScript"  type="text/javascript" src="js/jquery-easyui-1.5/locale/easyui-lang-zh_CN.js"></script>
<style type="text/css">
	a:link,a:visited{
 		text-decoration:none;  /*超链接无下划线*/
	}
	a:hover{
 		text-decoration:none;  /*鼠标放上去有下划线*/
	}
</style>
	<script type="text/javascript">
	 /*<![CDATA[*/ 
	            
	    function myformatter(date){
			var y = date.getFullYear();
			var m = date.getMonth()+1;
			var d = date.getDate();
			return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
		}
		function myparser(s){
			if (!s) return new Date();
			var ss = (s.split('-'));
			var y = parseInt(ss[0],10);
			var m = parseInt(ss[1],10);
			var d = parseInt(ss[2],10);
			if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
				return new Date(y,m-1,d);
			} else {
				return new Date();
			}
		}
     function formatCol(val,row)
     {
    	 if(row.id!='sum')
    	 return '<a href="#" onclick="showcar(\''+row.id+'\')">查看</a>&nbsp;&nbsp;<a href="#" onclick="printOrder(\''+row.id+'\')">打印</a>&nbsp;&nbsp;<a href="#" onclick="delOrder(\''+row.id+'\')">删除</a>';
     }
     
     function delOrder(orderid)
     {
    	 var url ="delOrder?orderid="+orderid;
		 $.get(url, function(data){
			 mysearch();
		 });
     }
     function formatColumn(val,row){
	   if(row.score!="0" && row.id!='sum')
		return '<a href="#"  onclick="getEvaluate(\''+row.orderid+'\',\''+row.foodname+'\')">查&nbsp;&nbsp;看</a>';
	}
     
     function mysearch()
     {
    	 var sdate = $('#sdate').datebox('getValue');
    	 var edate = $('#edate').datebox('getValue');
    	 
    	 
    	 var startD = new Date(Date.parse(sdate.replace(/-/g,"/")));
    	 var endD   = new Date(Date.parse(edate.replace(/-/g,"/")));
    	 var days = parseInt((endD.getTime()-startD.getTime()) / (1000 * 60 * 60 * 24));
    	 if(days > 31){
    	 	alert("日期范围应在一个月之内");
    	 	return false;
    	 }
    	 
    	 
    	 var flag = $('#flag').combobox('getValue');
    	 var desknum = $('#desknum').val();
    	 
    	 var url="getAllOrder?sdate="+sdate+"&edate="+edate+"&flag="+flag+"&desknum="+desknum;
    	 
    	 $('#aa').datagrid('loading');
    	 $.get(url, function(data){
			  	$("#aa").datagrid("loadData", data);
			  	 $('#aa').datagrid('loaded');
			});
    	 
     }
     
     function formatAmt(val,rowdata)
     {
    	 if(val=='0')
    	 {
    		return '<span style="color: #ff0033;">未下单</span>';	 
    	 }else if(val=='1')
    	 {
    		 return '<span style="color: #984b4b;">已结账</span>';
    	 }else if(val=='2')
    	 {
    		return '<span style="color: #00a600;">已下单</span>';	 
    	 }
     }
     
     function printOrder(orderid)
     {
    	 var url ="print_order?orderid="+orderid;
		 $.get(url, function(data){
		 });
     }
     
     function showcar(orderid)
	 {
         var url ="showOrderDetail?orderid="+orderid;
		 $.get(url, function(data){
			if(data.total!="0")
			{
				//$("#table").datagrid({showFooter: true});
				
				$("#data").datagrid("loadData", data);
				 $('#dlg').dialog('open');
			}else
			{
				//$("#table").datagrid({showFooter: false});
				var json = $.parseJSON("{\"total\":0,\"rows\":[],\"footer\":[]}");
				$("#data").datagrid("loadData", json);
				$('#dlg').dialog('open');
			}
			
		 });
	 }
     
     function getEvaluate(orgid,name)
	 {
		 $('#dlgev').panel({title: name});
		 
		 var url ="getEvaluate?orgid="+orgid;
		 
		 $.get(url, function(data){
			 
			 $("#icon").empty();

			if(typeof(data.score)=="undefined")
			{
				return;
			}else
			{
				var exp="input[name='ev'][value="+data.score+"]";
				$(exp).attr("checked",true);
				var html="";
				var len=parseInt(data.score)/25;
				len = parseInt(len);
				for(i=0;i<=len;i++)
				{
					html=html+'<img width="40px" height="40px" src="img/nice.jpg"/>';
				}
				len=5-len-1;
				for(i=0;i<len;i++)
				{
					html=html+'<img width="40px" height="40px" src="img/bad.jpg"/>';
				}
				$("#icon").append(html); 
				
			    $("#remark").val(data.remark);
			    
			    $('#dlgev').dialog('open');
			}
        	 
         });
	 }
	
	 $(document).ready(  
			  function(){
				  $('#dlg').dialog('close');
				  $('#dlgev').dialog('close');
				  
				  var curr_time = new Date(); 
				  $("#sdate").datebox("setValue",myformatter(curr_time)); 
				  $("#edate").datebox("setValue",myformatter(curr_time)); 
				  
				  $('#desknum').textbox('textbox').keydown(function (e) {
					 	mysearch();
				  });
				  
				  mysearch();
					
			  });
	 
	   
	 	
	 	/*]]>*/  
	</script>
	
	
</head>
<body>

<div style="position:absolute;left:0px;top:0px;width:700px;height:100%">
	<table class="easyui-datagrid" id="aa" title="订单分析" style="width:700px;height:100%"
			data-options="showFooter: true,rownumbers:true,singleSelect:true,toolbar:'#tb'">
		<thead>
			<tr>
				<th data-options="field:'idnum'" width="5%">桌号</th>
				<th data-options="field:'dname'" width="20%">桌名</th>
				<th data-options="field:'count'" width="5%">人数</th>
				<th data-options="field:'orgdate'" width="15%">日期</th>
				<th data-options="field:'orgtime'" width="15%">时间</th>
				<th data-options="field:'orgamt'" width="10%">金额</th>
				<th data-options="field:'flag',formatter:formatAmt" width="10%">状态</th>
				<th data-options="field:'id',align:'center',formatter:formatCol" width="20%">操作</th>
			</tr>
		</thead>
	</table>
	</div>
	
	<div id="tb" style="padding:2px 5px;">
		起始日期: <input class="easyui-datebox" id="sdate" data-options="formatter:myformatter,parser:myparser" style="width:95px"/>
		截至日期: <input class="easyui-datebox" id="edate" data-options="formatter:myformatter,parser:myparser" style="width:95px"/>
		订单状态:
		<select class="easyui-combobox" id="flag" panelHeight="auto" style="width:80px">
			<option value="3" selected="selected">全部</option>
			<option value="0">未下单</option>
			<option value="2">已下单</option>
			<option value="1">已结账</option>
		</select>
		桌号:
		<input class="easyui-textbox"  data-options="prompt:'输入桌号'" id="desknum" style="width:60px"/>
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="mysearch()">查询</a>
	</div>
	
	<div id="dlg" class="easyui-dialog" title="订单列表">
<table id="data" class="easyui-datagrid"  style="width:400px;height:350px;"
			data-options="singleSelect:true,collapsible:false,showFooter: true,rownumbers: true">
		<thead>
			<tr>
				<th data-options="field:'foodname'" width="30%">菜名</th>
				<th data-options="field:'price',editor:'text'" width="20%">价格</th>
				<th data-options="field:'count',editor:'text'" width="10%">数量</th>
				<th data-options="field:'orderid',align:'right',formatter:formatColumn" width="40%">评价</th>

			</tr>
		</thead>
	</table>
	</div>
	
	<div id="dlgev" class="easyui-dialog" title="客户评价"  style="width:310px;height:190px;">
		<table width="100%">
          	 		<tr><td align="center" >
          	 			极差<input type="radio" name="ev" value="0" />&nbsp;&nbsp;&nbsp;
          	 			差<input type="radio" name="ev" value="25" />&nbsp;&nbsp;&nbsp;
          	 			一般<input type="radio" name="ev" value="50" />&nbsp;&nbsp;&nbsp;
          	 			好<input type="radio" name="ev" value="75" />&nbsp;&nbsp;&nbsp;
          	 			非常好<input type="radio" name="ev" value="100" />&nbsp;&nbsp;&nbsp;
          	 			
          	 			</td></tr>
          	 		</table>
          	 		
          	 		<div>
						<textarea class="comments" id="remark" cols="32"   placeholder="味道如何评价一下吧！" rows="4"></textarea>
					</div>
					<div id="icon"></div>
	</div>
	
</body>
</html>